package com.my.kq.dao;

import com.my.kq.entity.Department;
import com.my.kq.uitl.BaseDAO;

import java.util.List;

public class DepartmentDao extends BaseDAO {
    public Department depselect(Integer zcnumbr) throws Exception {
        String sql="select * from department where departmentNumber=?";
        Object[]obj={zcnumbr};
        Department one = getOne(sql, new Department(), obj);
        return one;
    }

    public void depxg(Integer departmentNumber, String education1) throws Exception {
        String sql="update department set name=? where departmentNumber=? ";
        Object[]obj={education1,departmentNumber};
        int i = addOrupdOrdel(sql, obj);
    }

    public List<Department> selectdepartment() throws Exception {
        String sql="select * from department";
        // Object[]obj={dm.getDepartmentNumber(),dm.getName(),dm.getManager(),dm.getTelephone(),dm.getAddress(),dm.getNotes()};
        List<Department> list = getList(sql, new Department(), new Object[0]);
        return list;
    }
    //添加用户信息
    public void addDepartment(Department dm) throws Exception {
        String sql="insert into department values(null,?,?,null,?,?,?)";
        Object[]obj={dm.getDepartmentNumber(),dm.getName(),dm.getTelephone()
                ,dm.getAddress(),dm.getNotes()};
        addOrupdOrdel(sql,obj);
    }
    //修改用户信息
    public void updateDepartment(Department dm) throws Exception {
        String sql="update department set name=? , telephone=? , address=? , notes=? where id=?";
        Object[]obj={dm.getName(),dm.getTelephone()
                ,dm.getAddress(),dm.getNotes(),dm.getId()};
        addOrupdOrdel(sql,obj);

    }
    //删除用户信息
    public  void deleteDepartment(int id) throws Exception {
        String sql="delete from department where id=?";
        Object[]obj={id};
        addOrupdOrdel(sql,obj);
    }
    //分页查询
    public List<Department> getPage(int pageNo) throws Exception {
        String sql ="select * from department limit ?,?";
        //每页显示10条
        // (页码-1)*10 ,10
        Object[] obj ={(pageNo-1)*10,10};
        List<Department> list = getList(sql, new Department(), obj);
        return list;
    }
    //查询总记录条数
    public int  getCount() throws Exception {
        String sql = "select count(*) from department";
        return getCount(sql,new Object[0]);
    }
    //通过id查询department对象
    public Department getDepartment(int id) throws Exception {
        String sql="select * from department where id=?";
        Object[]obj={id};
        Department one = getOne(sql, new Department(), obj);
        return one;
    }
}
